package com.atues.bigdeciaml;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Main {
    public static void main(String[] args) {
        BigDecimal bigDecimal = new BigDecimal(0.1f);
        Float f = 0.1f;
        BigDecimal bigDecimal3 = new BigDecimal(f.toString());
        System.out.println(
                "bigDecimal3 = " + bigDecimal3);
        System.out.println(
                "bigDecimal = " + bigDecimal
        );

        BigDecimal bigDecimal1 = new BigDecimal("0.1");
        System.out.println(
                "bigDecimal1 = " + bigDecimal1
        );
        BigDecimal bigDecimal2 = BigDecimal.valueOf(0.1);
        System.out.println(
                "bigDecimal2 = " + bigDecimal2
        );
    }

    public void asdm() {
        BigDecimal a = new BigDecimal("1.0");
        BigDecimal b = new BigDecimal("0.9");
        System.out.println(a.add(b));// 1.9
        System.out.println(a.subtract(b));// 0.1
        System.out.println(a.multiply(b));// 0.90
        System.out.println(a.divide(b));// 无法除尽，抛出 ArithmeticException 异常
        System.out.println(a.divide(b, 2, RoundingMode.HALF_UP));// 1.11
    }
}
